package com.briup.corejava.day12;

import com.briup.corejava.day11.pojo.Student;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

/**
 * Set集合测试
 * TreeSet
 * 1、有序
 * 2、不重复
 * 3、没下标
 */
public class Test3 {
    public static void main(String[] args) {
        Set<Integer> set = new TreeSet<>();
        set.add(10);
        set.add(8);
        set.add(12);
        set.add(4);
        System.out.println(set);

        Set<String> stringSet = new TreeSet<>();
        stringSet.add("C");
        stringSet.add("Java");
        stringSet.add("C++");
        stringSet.add("Python");
        System.out.println(stringSet);

        Set<Student> studentSet = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.getAge() - o2.getAge();
            }
        });
        studentSet.add(new Student("tom",20));
        studentSet.add(new Student("terry",19));
        studentSet.add(new Student("adam",21));
        studentSet.add(new Student("lilith",22));
        studentSet.add(new Student("lilith",21));
        studentSet.add(new Student("lilith",23));
        // 快速遍历的方法：jdk8提供的
        studentSet.forEach(System.out::println);
    }
}
